package com.itheima.exerciseTest.method20_29.method23;

public class MyRubbable implements Runnable {
    private int count = 100;
    private static Object obj = new Object();


    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (count <= 0) {
                    break;
                } else {
                    System.out.print(Thread.currentThread().getName() + "正在买票...");
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    count--;
                    System.out.println("买票成功,还剩" + count + "张票");
                }
            }

        }
    }
}
